/*
 * @Description:GWP
 * @Author: qingyang
 * @Date: 2022-05-19 11:28:06
 * @LastEditors: qingyang
 * @LastEditTime: 2022-05-23 18:06:52
 */
import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'

import type { IGwpListResult, GetGwpListParams, IGwpAdd, IGwpVersionResult } from './model/gwpModel'

enum Api {
  // 因子库列表分页查询
  GET_GWP_LIST = '/inventory/gwpManager/pageGwp',
  // gwp HFCs&PFCs因子列表
  GET_GWP_FACTOR_LIST = '/inventory/gwpManager/pageFactors',
  // gwp版本列表获取
  GET_GWP_VERSION = '/inventory/inventoryFactor/getGwpVersion',
  // gwp详情
  GET_GWP_DETAIL = '/inventory/gwpManager/detail',
  // 修改gwp详情
  UPDATE_GWP_DETAIL = '/inventory/gwpManager/modify',
  // 删除Gwp
  DEL_GWP = '/inventory/gwpManager/delete',
  // 新增gwp
  ADD_GWP = '/inventory/gwpManager/save',
  // 根据类型查因子
  QUERY_FACTOR_LIST = '/inventory/inventoryFactor/list'
}

// 因子库列表分页查询
export const getGwpList = (
  params: GetGwpListParams & BasicPagingListParams
): Promise<BasicPagingListResult<IGwpListResult>> => get(Api.GET_GWP_LIST, params)

export const getGwpFactorList = (
  params: { factorName?: string; gwpId: string | number } & BasicPagingListParams
): Promise<BasicPagingListResult<IGwpListResult>> => get(Api.GET_GWP_FACTOR_LIST, params)

export const getGwpVersionList = (): Promise<IGwpVersionResult[]> => get(Api.GET_GWP_VERSION)

export const delGwp = (gwpId: string): Promise<void> => post(Api.DEL_GWP, { gwpId })
export const editGwp = (params: IGwpAdd): Promise<void> => post(Api.UPDATE_GWP_DETAIL, params)
export const addGwp = (params: IGwpAdd): Promise<void> => post(Api.ADD_GWP, params)
export const getGwpDetail = (gwpId: string | number): Promise<IGwpAdd> =>
  get(Api.GET_GWP_DETAIL, { gwpId })
